package cn.xuqiudong.rpc.common.util;

/**
 * 描述: class 工具类
 * @author Vic.xu
 * @date 2022-02-14 11:50
 */
public class XqdClassUtils {

    /**
     * 获取某个class的类加载器
     * @param clazz type
     * @return 类加载器
     */
    public static ClassLoader getClassLoader(Class<?> clazz) {
        ClassLoader classLoader = null;
        try {
            classLoader = Thread.currentThread().getContextClassLoader();
        } catch (Throwable ex) {
            // 获取当前线程的类加载器失败
        }
        if (classLoader == null) {
            // 获取当前类的加载器
            classLoader = clazz.getClassLoader();
            if (classLoader == null) {
                // 获取bootstrap类加载器
                try {
                    classLoader = ClassLoader.getSystemClassLoader();
                } catch (Throwable ex) {

                }
            }
        }

        return classLoader;
    }
}
